//
//  RCDiscountDetailNewCell.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-11-17.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCDiscountDetailNewCell.h"
#import "SMPageControl.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "NSArray+EX.h"
#import "UIImageView+WebCache.h"
#import "TTTAttributedLabel.h"
#import "NSAttributedString+LVAddition.h"
#import "NSString+NSString_Ex_.h"

#define kSwitchSceneDotActiveImage     @"image_discountDetail_dot_active.png"
#define kSwitchSceneDotInActiveImage   @"image_discountDetail_dot_inactive.png"
#define kBaomingImageFile              @"image_discountDetail_baoming.png"
#define kLineImageFile                 @"image_order_line.png"
#define kDotLineImageFile              @"image_merchantDetail_write_dotLine.png"
#define kVerticalLineImageFile         @"image_merchant_detail_verticalLine.png"
#define kStarActiveImageFile           @"image_discountDetail_star_active.png"
#define kStarInactiveImageFile         @"image_discountDetail_star_inactive.png"
#define kPhoneImageFile                @"image_discountDetail_telephone.png"


@interface RCDiscountDetailNewPictureHeaderCell()<UIScrollViewDelegate,RCDiscountHeaderCellDelegate>

@property(nonatomic,retain) UIScrollView *picScrollView;
@property(nonatomic,retain) SMPageControl *picPageControl;
@property(nonatomic,retain) UILabel     *originPriceLabel;
@property(nonatomic,retain) UILabel     *presentPriceLabel;
@property(nonatomic,retain) UIButton    *baomingImageView;
@property(nonatomic,retain) UIView      *priceLineImageView;
@property(nonatomic,retain) UIImageView *lineImageView;

@end

@implementation RCDiscountDetailNewPictureHeaderCell

@synthesize picScrollView = _picScrollView;
@synthesize picPageControl = _picPageControl;
@synthesize originPriceLabel = _originPriceLabel;
@synthesize presentPriceLabel = _presentPriceLabel;
@synthesize baomingImageView = _baomingImageView;
@synthesize priceLineImageView = _priceLineImageView;
@synthesize lineImageView = _lineImageView;
@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self placeHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)dealloc{
    
    self.delegate = nil;
    self.picScrollView = nil;
    self.picPageControl = nil;
    self.originPriceLabel = nil;
    self.presentPriceLabel = nil;
    self.baomingImageView = nil;
    self.priceLineImageView = nil;
    self.lineImageView = nil;
    [super dealloc];
}

-(void)placeHolderView{
    _picScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 188)];
    _picScrollView.backgroundColor = [UIColor clearColor];
    _picScrollView.delegate = self;
    _picScrollView.showsHorizontalScrollIndicator = NO;
    [self addSubview:_picScrollView];
    
    _picPageControl = [[SMPageControl alloc]init];
    CGFloat pageContWidth = (9+3)*3;
    _picPageControl.frame = CGRectMake((320-pageContWidth)/2, 188-11-9, pageContWidth, 9);
    _picPageControl.indicatorMargin = 3;
    [_picPageControl setUserInteractionEnabled:NO];
    _picPageControl.backgroundColor=[UIColor clearColor];
    _picPageControl.indicatorDiameter = 7;
    _picPageControl.numberOfPages = 3;
    [_picPageControl setPageIndicatorImage:[UIImage imageNamed:kSwitchSceneDotInActiveImage]];
    [_picPageControl setCurrentPageIndicatorImage:[UIImage imageNamed:kSwitchSceneDotActiveImage]];
    _picPageControl.currentPage = 0;
    [self addSubview:_picPageControl];
    
    _originPriceLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 202, 100, 23)];
    _originPriceLabel.backgroundColor = [UIColor clearColor];
    _originPriceLabel.textColor = [UIColor colorWithHex:0xffff8b00];
    _originPriceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:23];
    [self addSubview:_originPriceLabel];
    
    _presentPriceLabel = [[UILabel alloc]initWithFrame:CGRectMake(140, 208, 60, 16)];
    _presentPriceLabel.backgroundColor = [UIColor clearColor];
    _presentPriceLabel.textColor = [UIColor colorWithHex:0xff9b9b9b];
    _presentPriceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    [self addSubview:_presentPriceLabel];
    
    _priceLineImageView = [[UIView alloc]initWithFrame:CGRectMake(135, 216, 70, 1)];
    _priceLineImageView.backgroundColor = [UIColor colorWithHex:0xff9b9b9b];
    [self addSubview:_priceLineImageView];
    
    _baomingImageView = [[UIButton alloc]initWithFrame:CGRectMake(210, 200, 96, 31)];
    _baomingImageView.backgroundColor = [UIColor clearColor];
    [_baomingImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBaomingImageFile ofType:Nil]] forState:UIControlStateNormal];
    [_baomingImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBaomingImageFile ofType:Nil]] forState:UIControlStateHighlighted];
    [_baomingImageView addTarget:self action:@selector(baomingButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_baomingImageView];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 242, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:Nil]]];
    [self addSubview:_lineImageView];

}

-(void)bindData:(RCActivityDetailPicture *)pictureData{
    if (nil == pictureData) {
        return;
    }
    
    _picScrollView.hidden = YES;
    _picPageControl.hidden = YES;
    
    CGFloat height = 0.0;
    if (pictureData.pictureArray != nil && [pictureData.pictureArray count] >0) {
        _picPageControl.hidden = NO;
        _picScrollView.hidden = NO;
        NSInteger count = [pictureData.pictureArray count];
        _picScrollView.contentSize = CGSizeMake(320*count, 188);
        _picPageControl.numberOfPages = count;
        
        for (int i = 0; i < count; i++) {
            
            NSString *picUrl = [pictureData.pictureArray safeObjectAtIndex:i];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 188)];
            imageView.backgroundColor = [UIColor clearColor];
            [imageView setImageWithURL:[NSURL URLWithString:picUrl] placeholderImage:nil];
            [_picScrollView addSubview:imageView];
            [imageView release];
        }
        height += 188;
    }
    
    
    CGFloat width = 20.0;
    _originPriceLabel.hidden = YES;
    if (pictureData.activityPresentPrice > 0) {
        
        _originPriceLabel.hidden = NO;
        _originPriceLabel.text = [NSString stringWithFormat:@"￥%d",pictureData.activityPresentPrice];
        CGSize size = [_originPriceLabel.text sizeWithFont:_originPriceLabel.font constrainedToSize:CGSizeMake(200, 50)];
        CGRect rect = _originPriceLabel.frame;
        rect.size.width = size.width;
        rect.origin.y = height+14;
        _originPriceLabel.frame = rect;
        width = CGRectGetMaxX(_originPriceLabel.frame);
    }
    
    _presentPriceLabel.hidden = YES;
    _priceLineImageView.hidden = YES;
    if (pictureData.activityOriginPrice > 0) {
        _presentPriceLabel.hidden = NO;
        _priceLineImageView.hidden = NO;
        _presentPriceLabel.text = [NSString stringWithFormat:@"价值￥%d",pictureData.activityOriginPrice];
        
        CGSize size = [_presentPriceLabel.text sizeWithFont:_presentPriceLabel.font constrainedToSize:CGSizeMake(200, 50)];
        CGRect rect = _presentPriceLabel.frame;
        rect.origin.x = width + 10;
        rect.size.width = size.width;
        rect.origin.y = height + 18;
        _presentPriceLabel.frame = rect;
        
        _priceLineImageView.frame = CGRectMake(width+5, height+26, size.width+10, 1);
    }
    
    _baomingImageView.frame = CGRectMake(210, height + 12, 96, 31);
    _lineImageView.frame = CGRectMake(0, height + 54, 320, 1);
    
}

+(CGFloat)getCellHeight:(RCActivityDetailPicture *)pictureData{
    if (nil == pictureData) {
        return 0.0;
    }
    if (pictureData.pictureArray != nil && [pictureData.pictureArray count] >0) {
        return 243;
    }else{
       return 55;
    }
    
}

#pragma mark -

#pragma mark UIScrollView Delegate

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int count = _picPageControl.numberOfPages;
    if (count == 1) {
        return;
    }
    NSInteger pageNumber = 0;
    pageNumber = floor((scrollView.contentOffset.x - scrollView.frame.size.width/3)/scrollView.frame.size.width)+1;
    
    [_picPageControl setCurrentPage:pageNumber];
    
}

-(void)baomingButtonClicked{
    if (_delegate && [_delegate respondsToSelector:@selector(gotoOrderDiscountVC)]) {
        [_delegate gotoOrderDiscountVC];
    }
}

@end

@interface RCDiscountDetailNewDiscountInfoCell()

@property(nonatomic,retain) UIView *backgroundColorView;
@property(nonatomic,retain) TTTAttributedLabel *shopNameLabel;
@property(nonatomic,retain) TTTAttributedLabel *contentLabel;
@property(nonatomic,retain) UIImageView *dotLineImageView;
@property(nonatomic,retain) UILabel *buyNumberLabel;
@property(nonatomic,retain) UILabel *endTimeLabel;

@end

@implementation RCDiscountDetailNewDiscountInfoCell

@synthesize backgroundColorView = _backgroundColorView;
@synthesize shopNameLabel = _shopNameLabel;
@synthesize contentLabel = _contentLabel;
@synthesize dotLineImageView = _dotLineImageView;
@synthesize buyNumberLabel = _buyNumberLabel;
@synthesize endTimeLabel = _endTimeLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)dealloc{
    self.shopNameLabel = nil;
    self.contentLabel = nil;
    self.dotLineImageView = nil;
    self.buyNumberLabel = nil;
    self.endTimeLabel = nil;
    self.backgroundColorView = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _backgroundColorView = [[UIView alloc]initWithFrame:CGRectMake(13, 13, 294, 100)];
    _backgroundColorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_backgroundColorView];
    
    _shopNameLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 274, 16)];
    _shopNameLabel.backgroundColor = [UIColor clearColor];
    _shopNameLabel.textColor = [UIColor colorWithHex:0xff707070];
    _shopNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    _shopNameLabel.numberOfLines = 0;
    _shopNameLabel.leading = 6;
    [_backgroundColorView addSubview:_shopNameLabel];
    
    _contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 46, 274, 100)];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.textColor = [UIColor colorWithHex:0xff707070];
    _contentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _contentLabel.numberOfLines = 0;
    _contentLabel.leading = 6;
    [_backgroundColorView addSubview:_contentLabel];
    
    _dotLineImageView = [[UIImageView alloc]init];
    _dotLineImageView.backgroundColor = [UIColor clearColor];
    [_dotLineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kDotLineImageFile ofType:nil]]];
    [_backgroundColorView addSubview:_dotLineImageView];
    
    _buyNumberLabel = [[UILabel alloc]init];
    _buyNumberLabel.backgroundColor = [UIColor clearColor];
    _buyNumberLabel.textColor = [UIColor colorWithHex:0xff7b7a7a];
    _buyNumberLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [_backgroundColorView addSubview:_buyNumberLabel];
    
    _endTimeLabel = [[UILabel alloc]init];
    _endTimeLabel.backgroundColor = [UIColor clearColor];
    _endTimeLabel.textColor = [UIColor colorWithHex:0xff7b7a7a];
    _endTimeLabel.textAlignment = UITextAlignmentRight;
    _endTimeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [_backgroundColorView addSubview:_endTimeLabel];
}

-(void)bindData:(RCActivityDetailPicture *)pictureData{
    
    if (nil == pictureData) {
        return;
    }
    
    _shopNameLabel.text = pictureData.title;
    
    CGSize titleSize = [_shopNameLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 100) Leading:6];
    CGRect titleRect = _shopNameLabel.frame;
    titleRect.size.height = titleSize.height;
    _shopNameLabel.frame = titleRect;
    
    CGFloat height = CGRectGetMaxY(_shopNameLabel.frame);
    height +=15;
    
    _contentLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:pictureData.content]) {
        _contentLabel.hidden = NO;
        _contentLabel.text = pictureData.content;
        CGSize contentSize = [_contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 2000) Leading:6];
        CGRect rect = _contentLabel.frame;
        rect.origin.y = height;
        rect.size.height = contentSize.height;
        _contentLabel.frame = rect;
        
        height = CGRectGetMaxY(_contentLabel.frame);
        height +=13;
    }
    
    _dotLineImageView.frame = CGRectMake(0, height, 294, 1);
    height +=1;
    
    _buyNumberLabel.hidden = YES;
    _endTimeLabel.hidden = YES;
    if (pictureData.activitySignUp > 0 || ![NSString stringIsNullOrEmpty:pictureData.endTime]) {
        
        height +=10;
        if (pictureData.activitySignUp > 0) {
            _buyNumberLabel.hidden = NO;
            _buyNumberLabel.text = [NSString stringWithFormat:@"%d人购买",pictureData.activitySignUp];
            _buyNumberLabel.frame = CGRectMake(10, height, 200, 12);
        }
        
        if (![NSString stringIsNullOrEmpty:pictureData.endTime]) {
            _endTimeLabel.hidden = NO;
            _endTimeLabel.text = pictureData.endTime;
            _endTimeLabel.frame = CGRectMake(150, height, 134, 12);
        }
        height+=12;
    }
    
    height +=10;
    _backgroundColorView.frame = CGRectMake(13, 13, 294, height);
}

+(CGFloat)getCellHeight:(RCActivityDetailPicture *)pictureData{
    if (nil == pictureData) {
        return 0.0f;
    }
    
    CGFloat height = 10;
    
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 274, 16)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor colorWithHex:0xff707070];
    label.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    label.numberOfLines = 0;
    label.leading = 6;
    label.text = pictureData.title;
    
    CGSize titleSie = [label.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 100) Leading:6];
    
    height +=titleSie.height;
    height +=15;
    [label release];
    
    if (![NSString stringIsNullOrEmpty:pictureData.content]) {
        TTTAttributedLabel  *contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 46, 274, 100)];
        contentLabel.backgroundColor = [UIColor clearColor];
        contentLabel.textColor = [UIColor colorWithHex:0xff707070];
        contentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
        contentLabel.numberOfLines = 0;
        contentLabel.leading = 6;
        
        contentLabel.text = pictureData.content;
        CGSize contentSize = [contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 2000) Leading:4];
        
        [contentLabel release];
        
        height += contentSize.height;
        height +=13;
    }
    
    
    height +=1;
    
    if (pictureData.activitySignUp > 0 || ![NSString stringIsNullOrEmpty:pictureData.endTime]) {
        
        height +=10;
        
        height+=12;
    }
    
    height +=10;
    
    return height +13;
}

@end


@interface RCDiscountDetailNewShopInfoCell()<UIActionSheetDelegate>

@property(nonatomic,retain) UIView *backgroundColorView;
@property(nonatomic,retain) UILabel *titleNameLabel;
@property(nonatomic,retain) UILabel *shopNameLabel;
@property(nonatomic,retain) UIView *starView;
@property(nonatomic,retain) TTTAttributedLabel *addressLabel;
@property(nonatomic,retain) UIImageView *dotLineImageView;
@property(nonatomic,retain) UIButton *telephoneButton;
@property(nonatomic,retain) UIImageView *dotVerticalLine;
@property(nonatomic,retain) UIWebView *phoneWebView;
@property(nonatomic,retain) RCActivityDetailShopInfo *detailDataModel;

@end

@implementation RCDiscountDetailNewShopInfoCell

@synthesize backgroundColorView = _backgroundColorView;
@synthesize shopNameLabel = _shopNameLabel;
@synthesize titleNameLabel = _titleNameLabel;
@synthesize starView = _starView;
@synthesize dotLineImageView = _dotLineImageView;
@synthesize addressLabel = _addressLabel;
@synthesize telephoneButton = _telephoneButton;
@synthesize dotVerticalLine = _dotVerticalLine;
@synthesize phoneWebView = _phoneWebView;
@synthesize parentVC = _parentVC;
@synthesize detailDataModel = _detailDataModel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)dealloc{
    self.shopNameLabel = nil;
    self.titleNameLabel = nil;
    self.dotLineImageView = nil;
    self.starView = nil;
    self.addressLabel = nil;
    self.telephoneButton = nil;
    self.dotVerticalLine = nil;
    self.backgroundColorView = nil;
    self.phoneWebView = nil;
    self.parentVC = nil;
    self.detailDataModel = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    
    _backgroundColorView = [[UIView alloc]initWithFrame:CGRectMake(13, 13, 294, 100)];
    _backgroundColorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_backgroundColorView];
    
    _titleNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 274, 16)];
    _titleNameLabel.backgroundColor = [UIColor clearColor];
    _titleNameLabel.textColor = [UIColor colorWithHex:0xff707070];
    _titleNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [_backgroundColorView addSubview:_titleNameLabel];
    
    
    _dotLineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 36, 294, 1)];
    _dotLineImageView.backgroundColor = [UIColor clearColor];
    [_dotLineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kDotLineImageFile ofType:nil]]];
    [_backgroundColorView addSubview:_dotLineImageView];
    
    _shopNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 47, 220, 12)];
    _shopNameLabel.backgroundColor = [UIColor clearColor];
    _shopNameLabel.textColor = [UIColor colorWithHex:0xff707070];
    _shopNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    [_backgroundColorView addSubview:_shopNameLabel];
    
    _starView = [[UIView alloc]initWithFrame:CGRectMake(10, 64, 220, 8)];
    _starView.backgroundColor = [UIColor clearColor];
    [_backgroundColorView addSubview:_starView];
    
    _addressLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 77, 220, 100)];
    _addressLabel.backgroundColor = [UIColor clearColor];
    _addressLabel.textColor = [UIColor colorWithHex:0xff707070];
    _addressLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _addressLabel.numberOfLines = 0;
    _addressLabel.leading = 4;
    [_backgroundColorView addSubview:_addressLabel];
    
    _dotVerticalLine = [[UIImageView alloc]initWithFrame:CGRectMake(235, 37, 1, 100)];
    _dotVerticalLine.backgroundColor = [UIColor clearColor];
    [_dotVerticalLine setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kVerticalLineImageFile ofType:nil]]];
    [_backgroundColorView addSubview:_dotVerticalLine];
    
    
    _telephoneButton = [[UIButton alloc]initWithFrame:CGRectMake(235, 37, 59, 100)];
    _telephoneButton.backgroundColor = [UIColor clearColor];
    [_telephoneButton setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kPhoneImageFile ofType:nil]] forState:UIControlStateNormal];
    [_telephoneButton setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kPhoneImageFile ofType:nil]] forState:UIControlStateHighlighted];
    [_telephoneButton addTarget:self action:@selector(telephoneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_backgroundColorView addSubview:_telephoneButton];
}

-(void)bindData:(RCActivityDetailShopInfo *)shopData{
    
    if (nil == shopData) {
        return;
    }
    self.detailDataModel = shopData;
    _titleNameLabel.text = @"商家信息";
    
    _shopNameLabel.text = shopData.shopName;
    UIImage *activeStarImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kStarActiveImageFile ofType:nil]];
    UIImage *inactiveStarImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kStarInactiveImageFile ofType:nil]];
    
    for (int i = 0; i < 5; i++) {
        UIImageView *starImageView = [[UIImageView alloc]initWithFrame:CGRectMake(8*i, 0, 7, 8)];
        [starImageView setImage:shopData.score >= i+1 ? activeStarImage : inactiveStarImage];
        [_starView addSubview:starImageView];
        [starImageView release];
        
    }
    _addressLabel.text = shopData.address;
    CGSize contentSize = [_addressLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(220, 2000) Leading:4];
    CGRect rect = _addressLabel.frame;
    rect.size.height = contentSize.height;
    _addressLabel.frame = rect;
    
    CGFloat height = CGRectGetMaxY(_addressLabel.frame);
    height +=10;
    height -=37;
    
    _dotVerticalLine.hidden = YES;
    _telephoneButton.hidden = YES;
    if (![NSString stringIsNullOrEmpty:shopData.telePhone]) {
        _dotVerticalLine.hidden = NO;
        _telephoneButton.hidden = NO;
        
        _dotVerticalLine.frame = CGRectMake(235, 37, 1, height);
        _telephoneButton.frame = CGRectMake(236, 37, 58, height);
    }
    
    
    _backgroundColorView.frame = CGRectMake(13, 11, 294, height+37);
}

+(CGFloat)getCellHeight:(RCActivityDetailShopInfo *)shopData{
    if (nil == shopData) {
        return 0.0f;
    }

    CGFloat height = 77;
    TTTAttributedLabel  *contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 77, 220, 100)];
    contentLabel.backgroundColor = [UIColor clearColor];
    contentLabel.textColor = [UIColor colorWithHex:0xff707070];
    contentLabel.font = [UIFont fontWithName:kFontNameHeiti size:12];
    contentLabel.numberOfLines = 0;
    contentLabel.leading = 4;
    
    contentLabel.text = shopData.address;
    CGSize contentSize = [contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(224, 2000) Leading:4];
    
    height += contentSize.height;
    height +=10;
    [contentLabel release];
    
    return height +11;
}

-(void)telephoneButtonClicked{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"电话" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    NSString *phoneString = self.detailDataModel.telePhone;
    phoneString = [phoneString stringByReplacingOccurrencesOfString:@"，" withString:@","];
    NSArray *phoneNumberArray = nil;
    NSRange range = [phoneString rangeOfString:@","];
    if (range.location != NSNotFound) {
        phoneNumberArray = [phoneString componentsSeparatedByString:@","];
    }else{
        NSRange range = [phoneString rangeOfString:@"/"];
        if (range.location != NSNotFound) {
            phoneNumberArray = [phoneString componentsSeparatedByString:@"/"];
        }else{
            phoneNumberArray = [phoneString componentsSeparatedByString:@" "];
        }
        
    }
    
    for (NSString *content in phoneNumberArray) {
        if ([NSString stringIsNullOrEmpty:content]) {
            continue;
        }
        [sheet addButtonWithTitle:content];
    }
    sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"取消"];
    [sheet showFromTabBar:self.parentVC.tabBarController.tabBar];
    [sheet release];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
        if (_phoneWebView == nil) {
            _phoneWebView = [[UIWebView alloc] init];
            
        }
        title = [title stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSURL *phone = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",title]];
        
        [_phoneWebView loadRequest:[NSURLRequest requestWithURL:phone]];
    }
}

@end

@interface RCDiscountDetailNewContentTitleCell()

@property(nonatomic,retain)UILabel *titleNameLabel;
@property(nonatomic,retain)UIView  *backgroundColorView;

@end

@implementation RCDiscountDetailNewContentTitleCell

@synthesize titleNameLabel = _titleNameLabel;
@synthesize backgroundColorView = _backgroundColorView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)dealloc{
    self.titleNameLabel = nil;
    self.backgroundColorView =nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    _backgroundColorView = [[UIView alloc]initWithFrame:CGRectZero];
    _backgroundColorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_backgroundColorView];
    
    _titleNameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    _titleNameLabel.backgroundColor = [UIColor clearColor];
    _titleNameLabel.textColor = [UIColor colorWithHex:0xff707070];
    _titleNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [_backgroundColorView addSubview:_titleNameLabel];
}

-(void)bindData:(NSString *)titleName{
    if ([NSString stringIsNullOrEmpty:titleName]) {
        return;
    }
    _backgroundColorView.frame = CGRectMake(13, 11, 294, 36);
    _titleNameLabel.frame = CGRectMake(10, 10, 274, 16);
    _titleNameLabel.text = titleName;
}

+(CGFloat)getCellHeight{
    return 47;
}


@end


@interface RCDiscountDetailNewContentImageCell()

@property(nonatomic,retain)UIImageView *contentImageView;
@property(nonatomic,retain)UIView *backgroundColorView;

@end

@implementation RCDiscountDetailNewContentImageCell

@synthesize contentImageView = _contentImageView;
@synthesize backgroundColorView = _backgroundColorView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)createPlaceHolderView{
    
    _backgroundColorView = [[UIView alloc]initWithFrame:CGRectZero];
    _backgroundColorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_backgroundColorView];
    
    _contentImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 294, 313)];
    _contentImageView.backgroundColor = [UIColor clearColor];
    
    [_backgroundColorView addSubview:_contentImageView];
}

-(void)bindData:(NSString *)imageUrl{
    if ([NSString stringIsNullOrEmpty:imageUrl]) {
        return;
    }
    
    _backgroundColorView.frame = CGRectMake(13, 0, 294, 313);
    [_contentImageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
}

+(CGFloat)getCellHeight:(NSString *)imageUrl{
    if ([NSString stringIsNullOrEmpty:imageUrl]) {
        return 0.0f;
    }
    
    return 313.0f;
}

@end


@interface RCDiscountDetailNewNoticeCell()

@property(nonatomic,retain)TTTAttributedLabel *contentLabel;
@property(nonatomic,retain)UIView  *backgroundColorView;

@end

@implementation RCDiscountDetailNewNoticeCell

@synthesize contentLabel = _contentLabel;
@synthesize backgroundColorView = _backgroundColorView;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolderView];
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)dealloc{

    self.contentLabel = nil;
    self.backgroundColorView = nil;
    [super dealloc];
}

-(void)createPlaceHolderView{
    _backgroundColorView = [[UIView alloc]init];
    _backgroundColorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_backgroundColorView];
    
    _contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectZero];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.textColor = [UIColor colorWithHex:0xff707070];
    _contentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _contentLabel.numberOfLines = 0;
    _contentLabel.leading = 6;
    [_backgroundColorView addSubview:_contentLabel];
}

-(void)bindData:(RCActivityDetailNotice *)noticeData{
    if (nil == noticeData || [NSString stringIsNullOrEmpty:noticeData.content]) {
        return;
    }
    
    _contentLabel.text = noticeData.content;
    _contentLabel.frame = CGRectMake(10, 10, 274, 100);
    CGSize contentSize = [_contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 2000) Leading:6];
    CGRect rect = _contentLabel.frame;
    rect.size.height = contentSize.height;
    _contentLabel.frame = rect;
    
    CGFloat height = CGRectGetMaxY(_contentLabel.frame);
    
    height +=10;
    _backgroundColorView.frame = CGRectMake(13, 11, 294, height);
}

+(CGFloat)getCellHeight:(RCActivityDetailNotice *)noticeData{
    if (nil == noticeData || [NSString stringIsNullOrEmpty:noticeData.content]) {
        return 0.0f;
    }
    
    CGFloat height = 10;
    TTTAttributedLabel  *contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 274, 100)];
    contentLabel.backgroundColor = [UIColor clearColor];
    contentLabel.textColor = [UIColor colorWithHex:0xff707070];
    contentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    contentLabel.numberOfLines = 0;
    contentLabel.leading = 6;
    
    contentLabel.text = noticeData.content;
    CGSize contentSize = [contentLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(274, 2000) Leading:4];
    
    height += contentSize.height;
    height +=10;
    
    height +=11;
    
    height +=15;
    [contentLabel release];
    
    return height;
}

@end

